import axios  from 'axios'
import nprogress from 'nprogress'
import "nprogress/nprogress.css"
import store from '@/store'

export const request = axios.create({
    baseURL: process.env.VUE_APP_API,
    timeout: 10000
})

request.interceptors.request.use((config) => {
    nprogress.start()
    //添加用户临时信息
    config.headers.userTempId = store.state.user.userTempId
    //添加token
    config.headers.token = store.state.user.token
    return config

}, (error) => {
    nprogress.done()
    return Promise.reject(error.message)
})

request.interceptors.response.use((response) => {
    // console.log(response.data.data);
    nprogress.done()
    return response.data.data

}, (error) => {
    nprogress.done()
    Promise.reject(error.message)
})